home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / dcom / modems-part1 / 9068 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  19.8 KB

  1. Path: EU.net!sun4nl!stout!gerard
  2. From: gerard@sbu.stork.nl (Gerard van Draanen)
  3. Newsgroups: comp.sys.palmtops,alt.comp.hardware.homebuilt,comp.dcom.modems,comp.os.msdos.programmer,comp.sys.handhelds,comp.sys.ibm.pc.hardware.comm,sci.electronics
  4. Subject: RFC -- Input    IR-RC on a (Sharp PC300) PC ; remote control
  5. Keywords: Sharp, PC3k, IRDA, IR, RC, Assembly, Req for comment, LED, Sample, Bit
  6. Message-ID: <3021@stout.UUCP>
  7. Date: 25 Mar 96 12:44:51 GMT
  8. Followup-To: comp.sys.palmtops
  9. Organization: Stork Bepak B.V., Utrecht, NL
  10.  
  11. Hello Netters,
  12.  
  13. I'm currently working on getting my Sharp PC3000 Handheld computer to be able
  14. to send and receive via an IR interface.
  15.  
  16. TX/RX  for (regular) DataComm....
  17. CTS/RI for Bitstream information.
  18.  
  19. I could use a little help on a couple of subjects.....
  20. - How to properly setup some electronics around the IR-receiver, for it to 
  21.   be able to capture ~40 kHz IR signals into binary (+or -10V ) signals 
  22.   suitable for detection on a PC's rs232 port.
  23. - How to optimize the (sample) assembly language program I made, so it 
  24.   becomes more useful...
  25.  
  26. And maybe.... one of you people has done all this before... If so, I'd be 
  27. glad to hear about the availability of such 'sample' software.
  28.  
  29. The idea, is that I'm doing a 'raw' sampling and storing, with oversampling
  30. to be able to repeat the IR signal through output across a IR-Led in 
  31. parallel to the PC's speaker.
  32.  
  33. Here's the information, and analysis so-far.
  34. Feel free to add to this, or to give me pointers on possible assy language
  35. improvements.....
  36. Let's get this stuff going... my preliminary test are very hopeful..
  37.  
  38. Thanks in advance for your further input,
  39. Gerard.
  40.  
  41. ===================   _____ Mngr.Tech.Autom. / ==============================
  42. Gerard van Draanen.  /  _  _   _, __   _, __/  How come, after all books read
  43. gerard@sbu.stork.nl /   / /-' /  /_/  /  /_/   You still can't go by the book
  44. =================== ~~~~  `~ ~     ~ ~     ~   ==============================
  45. --
  46.  
  47. Gerard van Draanen             -- IR.TXT --                         -1-
  48. '960308  '960325
  49.  
  50. Wireless communication between (PC) equipment is being used more and more.
  51. A number of new PC's are supplied standard with IRDA interface.
  52.  
  53. There's a possibility, with relavively simple H/W adjustment to create such
  54. a communication link without cable.
  55. Esp. in an industrial environment, an IR communication can be an alternative
  56. to reduce on cabling (and installation) cost in a couple of situations.
  57.  
  58. Simply put, the wireless comm. comes down to an IR-led & IR-receiver.
  59. In some cases, 1-way traffic will suffice.
  60. (Remote-Control of auxillary equipment, displays, Barcode-lezers, TVs etc. )
  61.  
  62. A sender/receiver thus has 2 specific types of input/output:
  63.   - Bitstream ... Data to be sampled without further interpretation
  64.                 . User assigns 'logical meaning' to a sample
  65.                .. Sample can be repeated as output
  66.                     -- on a different location
  67.                     -- on a different time
  68.                   to get a reaction from equipment, equal to a situation of
  69.                   sending the original sample directly.
  70.                .. Multiple samples can be combinded, or timed, to make more
  71.                   more complicatied input/output situations.
  72.   - Datacomm  ... (ASCII) data is transferred, WITH its usual timing / meaning.
  73.  
  74. There are a couple of ways to go about sending and receiving the signals...
  75.   - Dedicated external Harware, capable of 'understanding' bitstream samples
  76.   - Non-dedicated hardware, but extensive s/w to 'understand' the sample
  77.   - A 'stupid' simple device, giving bitstream to be repeated
  78. I'll go for the 'stupid' device... I don't want to add external h/w to
  79. achieve my intended purpose here...
  80.  
  81. Basic possibilities are  IR-Led in parallel to speaker
  82.                              or on RTS / DTR output of Serieal port
  83.                           and/or   TX output of Serial port
  84.                              or on one of the 'OUT' bits on the Parallel port
  85.                          IR-receiver or RI/ DCD/ CTS/ DSR from Serieel poort
  86.                               and/or on RX input of Serial port.
  87.                                   or on one of the 'IN' bits on the Parallel port.
  88. A basic need, is to create a fixed sample rate, not related to PC speed.
  89. The baudrate generator in a PC can function perfectly for this..
  90. But... the sample rate needs to be in the 80--120kHz range (oversampling), and
  91. that needs a bit of extra thought on the PC's end.
  92.  
  93. For Datatcomm, using TX/RX on the serial port should suffice, without further
  94. software adjustments. This will enable operation similar to a 3-wire connection.
  95.  
  96. Note:One (1) sender can reach multiple receivers
  97.  
  98. The TX/RX comm can not be used for a Bitstream, since the 'framing' information
  99. will interfere with the signal to be sent.
  100. The original equipment will not have facilities to strip or add these bits.
  101. In the 'BitStream' case, signals from RTS (out) and RI (in) pins are preferred.
  102. /O.
  103.  
  104.  
  105. Gerard van Draanen             -- IR.TXT --                         -2-
  106.  
  107. As background information I've studied a number of magazines and books.
  108. I don't have (any) understanding of the IR-RC basics, other than what I've
  109. read from these articles...
  110. References:
  111.   Ct magazine Nr7 + Nr8 '91
  112.   Elektuur 4-'94 en 11-'94  Subj. IR-RC op PC, en Philips RC5 codes
  113. And for some detail info on the PC's serial port and h/w configuration:
  114.   Crafting C tools for the IBM PCs    ISBN: 0-13-188418-2 025
  115.   (Joe Campbell, Prentice hall)
  116.   The IBM PC & PS/2                   ISBN: 1-55615-131-4
  117.   (Peter Norton, Microsoft Press)
  118.  
  119. Note:Rohm Electronics GmbH; Karl-Arnold-Str 15;47877 Willich-Munchheide;
  120.      Duitsland... Tel +49-2154-9210 (Fax : +49-21544-9214-00)
  121.      Has an IR (IrDA1.0) compact IC for Send/Rcv+Modulatie: RPM 800CB
  122.      2k4 t/m 115k2 Transfer rate in mini housing..(12*5.5*4.5 mm)
  123.  
  124. An IR-RC signal is generally made-up out of a modulated base frequency in
  125. 31, 38, or 40 kHz range. '0' & '1's are then 'Gated' on the base frequency.
  126.  
  127. The setup of the Data-signal is...
  128.     ---init----[pause1]___data_____
  129. or  ---init----[pause1]...header...[pause2]___data___[pause3]
  130.         the possibly repeating part is :   ..................
  131. So, there is a difference in 'one-time' signals and signals being repeated
  132. until the 'button' is released. The signal content is Factory specific.
  133. Numerous codes, combinations, timings etc. exist for all the various
  134. manufacturers.
  135. ==========
  136. Some background info on the Alarm timer, Serial port and Sound/Speaker:
  137. ==========
  138. Alarm Interrupt (vector 4A) is at 0:128 in byte-reversed format
  139. v.b. PC3k: 02 2f C4 25
  140. So, its a reference to an alarm-handling function at 25C4:2F02
  141. Such a routine can be used to -timed- send a specific IR-RC code.
  142. Further interaction with this service requires some further study.
  143.  
  144. A possible base for time can be the built-in
  145. 8253 programmable interval timer:
  146.   Ch-0 = 18.2/sec PC clock timer output
  147.   Ch-1 = Ram-refresh
  148.   Ch-2 = Speaker frequency <== Basic freq via programmable devider.
  149.   Ch-3 = ?, often via NMI
  150.  
  151. Ch-2 can be used for Sound-generation (and -thus- for IR led control)
  152. 8253-5 Input signal is 1.19xxx MHz, output is via Devider
  153. Programing the Devider:
  154.   OUT 43, B6   <- Prepare 8253 to accept devider
  155.   OUT 42, 0A   <- Low order
  156.   OUT 42, 00   <- High order
  157. Will giva ca. 100kHz signal to Sound-Amp
  158. That signal .... we should be able to pick up
  159.   OUT43, OUT42       8253-5  --> Ch-2 ---->
  160.                                                  --> Speaker
  161.                             OUT 61, xx  -->
  162.                                     Bit 0= pulses on Ch-2 to speaker
  163.                                     Bit 1= 1of0 setting of Speaker bit
  164. INP 61 AND FC (As to avoid damaging other INP61 bits)
  165.   ... IF it would be possible to READ the current state of the Ch-2 status,
  166.       THEN that state could function as a timing signal....
  167.   However... I have found no possibility to READ the signal state.
  168.  
  169. Gerard van Draanen             -- IR.TXT --                         -3-
  170.  
  171. ==========
  172. As an alternate timing source, we can use the PC's baudrate-generator
  173. in the PC RS232 poort.
  174. PC adress   0:400-401  ==> COM 1 adress   (Normally $3F8)  ==> UART-BASE
  175.             0:402-403  ==> COM 2 adress
  176.  
  177. UART-BASE +0  = TX/RX byte buffer
  178.              en
  179.            0  = BAUD_MSByte... Before adressing this... first
  180.            1  = BAUD_LSByte    UART-BASE+3 -> MSbit=1    Devid.0==> 115k2 baud
  181.              en                                          (So ca. 10k CPS)
  182.                             7654 3   2    1     0
  183.            1  = INTR-Enable      232 Stat TX    TX
  184.                                           Empty Ready
  185.                 (With this, an INT routing can be calle at each Byte TX/RX )
  186.                             76543  21                      0
  187.            2  = INT-ID      xxxxx  00 = 232 Input          INT-pending
  188.                                    01 = TX
  189.                                    10 = RX
  190.                                    11 = Serialization error
  191.                 (Crafting C Tools... pag 379  for INT => Char->Buffer )
  192.  
  193.            3  = DATA-FORMAT   7     6     5      4       3      2    1 0
  194.                               Baud  Set   Stick  Even    Parity Stop Word
  195.                               Latch Break Parity (0=Odd) Enable bits Length 5-8
  196.                             765     4     3      2       1      0
  197.            4  = CONTROL             Loop  !IRQ   User    RTS    DTR
  198.                                     Test
  199.                               7     6     5      4       3      2     1     0
  200.            5  = SIO-STAT      x     XMIT  XMIT   RX'd    Frame  Par.  Over  Data
  201.                                     SHreg Hold    a      Error  Error Run   Ready
  202.                                     Empty Empty  BREAK
  203.                 (Ready to send when SIO-STAT = "0010 0000" )
  204.                               7     6     5      4       3      2     1     0
  205.            6  = STAT-232      DCD   RI    DSR    CTS     DELTA  DELTA DELTA DELTA
  206.                                                          DCD    RI    DSR    CTS
  207.                 (Reading STAT-232 resets the DELTA.. [latch sig. change] )
  208.  
  209. Now, by using SIO-STAT while sending and receiving , a fixed time-base for the
  210. bitstream sample can be achieved.
  211. Per dataBIT on the TX line, a corresponding BIT on the CONTROL line (CTS) can
  212. be sent. So the BIT rate on the Serial connector is needed.
  213.  
  214.   _____|~|XXXXXXXXp|~|__|~|xxxxxxxxp|~|____
  215.           Data      Stop   Data      Stop
  216.         Start     Par    Start     Par
  217.                      ____ = Time available for setup of next byte
  218. When a fixed 01010101010101 pattern can be achieved, than, that signal can be
  219. fed-back to one of the pins, and the next BIT on the IR-led can be set up.
  220. Sending    "01010101" with EVEN parity (results in 0) & 1 stop-bit will give..
  221.            10101010101_10101010101_10101010101_ on the TX line.... SO
  222.                      (1)         (1)         (1)on the XMIT Hold empty reg
  223.  
  224. XMIT Hold empty can function as a trigger for the (same) next Byte for the
  225. TX line.... On each -1-0-1- transition of the TX line, a corresponding
  226. bit from the bitstream can be handled.
  227.  
  228. Gerard van Draanen             -- IR.TXT --                         -4-
  229.  
  230. In principle, storing the sample Bitstream data can be done with simple
  231. Assembler SHL, RLC, STC, CLC, SAL & JC [decr_ptr] assignments..
  232. By first shifting a '1', then... when this first bit rolls out into the 'Carry'
  233. bit, this can function as a trigger to decrement the byte-pointer..
  234. So... not much overhead is needed to store the binary data
  235.  
  236.       [       ] [       ]1[10011001] [10000111]
  237.       0         <====                 First set of 8 samples
  238.       Determ.   Fill   ^   Second set of 8 samples
  239.       Max.len   dire-  ^ Carry bit ==> Decrement byte-pointer
  240.       Sample    ction  Current position byte-pointer
  241.  
  242. The very first bit in a sample is always a '1', and its presece activates the
  243. further sampling.
  244. At 100kHz we have ca 10 microseconds for data handling...so... not much.
  245.  
  246. After a sample has been taken, the first valid (#'0') postion will determine
  247. the length of the sample to be stored.
  248.  
  249. Possible H/W electronic..
  250.         Z?SState-relais .. or manual
  251.   =-----3CD RTS       Datacomm. RTS v:   TX-> IR-led
  252.  IR-Led @Y                              DTR->IR-Rcv->RX         <==Rcv op RX
  253.   =|<--o\ o DTR                                            (equal to 3-wire)
  254.          \o TX
  255.  IR-Rcv               Bitstream RTS ^:   TX-> RI (Timing)
  256.   +->|-o\ o CTS                         DTR-> IR-led
  257.   |      \o RX                          RTS->IR-Rcv->CTS        <==Rcv op CTS
  258.   |
  259.   +----o\ o RTS         Note: The IR receiver needs a bit of electronics to
  260.          \o DTR               amplify/digitize the incoming signal.
  261.  Timing
  262.   +-ZDDD?-- TX        RI+ SIO_STAT( Xmit-empty) gives timing for Send/Recv
  263.   | @DDDY             by setting up a fixed 10101010 pattern on TX at 115k2
  264.   +->|----- RI
  265.  
  266.   Because the RI (ring indicator) is seldomly used, this part of the h/w can
  267.   be put INSIDE of the PC. This allows the detection of a timing signal
  268.   without external hardware. When the IR-led is in parallel to the speaker,
  269.   than that can be used for Sending information.
  270.  
  271. With all this background information... I've set up an assembly language
  272. test program, and tried that in debug.  (my irgt.com uuencoded-included).
  273. I connected the TX line to the RI line, and alternated the CTS with that
  274. connection.
  275. It seems to work quite nicely, I get anticipated results till 57k6, so I
  276. guess by assembly routines could still be a bit quicker or the way I had
  277. set up for testing was not optimal for the full 115k2 sampling rate.
  278.  
  279. So... I'm possibly in need for someone to optimize the following ir.asm
  280. assembly programming... I may have been quite 'clumsy' with my selection of
  281. instructions. This is due to lack of experience in the assy-programming field.
  282.  
  283. ;Gerard van Draanen             -- IR.TXT --                         -5-
  284. ;Logical setup / flow:
  285.  
  286. $3F8 = SIO_BASE
  287. SIO_TX_RX =0
  288. SIO_BD_MSB=0
  289. SIO_BD_LSB=1
  290. SIO_DA_FMT=3
  291. SIO_CTRL  =4
  292. SIO_STAT  =5
  293. SIO_STAT_I=6
  294.  
  295. RX_MASK   =1
  296. TX_MASK   =$20
  297. RI_MASK   =$40
  298. CTS_MASK  =$10
  299.  
  300. ;CLEAR A 16k+$FF BUFFER AT _OFFSET
  301. ;Debug instruction: FDS:2000L5000 00
  302.  
  303. ;Variables at fixed (offset) adress $2000 [SI]
  304. _OFFSET :
  305. MOV SI,_OFFSET
  306. DW 0000     ; SAFETY=0     at SI+0 and SI+1
  307. DB 00       ; OLDRI=0      at SI+2
  308. DB 00       ; 1ST1=0       at SI+3
  309. DW 0000     ; SAMPSIZE=0   at SI+4 and SI+5
  310.  
  311. MOV BX,4FFF     ; Max buffer length (at SI + $FF )
  312. MOV CX,0        ; Timeout for 1st '1' sample  (Loop to RD_RI )
  313.  
  314. ;====
  315. ;Setup 115k2 rate , 1 stopbit, 7 databits, Even parity for 10101010101 stream
  316. ;====
  317. ;Read status, set Bit7, load Baudrate, clr Bit7
  318. mov dx,3fb
  319. in  al,dx
  320. ;
  321. ; Check if you like
  322. ; Latch bit on
  323. mov al,9a
  324. out dx,al
  325. mov dx,3f8
  326. ; LSB Baud
  327. ;      xx update for testing 60=1200bd, 0c=9600bd, 06=19k2 01=115k2
  328. mov al,01
  329. out dx,al
  330. inc dx
  331. ; MSB Baud
  332. mov al,00
  333. out dx,al
  334. mov dx,03fb
  335. in  al,dx
  336. ; Latch bit off
  337. and al,7f
  338. out dx,al
  339.  
  340. ;====
  341. RTS_nDTR = 0A    ; No interrupts, RTS^  DTRv
  342. ;====
  343. SET_SIO:MOV DX,SIOBASE+SIO_CTRL
  344.         MOV AL,RTS_nDTR
  345.         OUT DX,AL
  346.         ;
  347.  
  348. ;Gerard van Draanen             -- IR.TXT --                         -6-
  349.         ;
  350. TX_RDY: MOV DX,SIOBASE+SIO_STAT       ; Test --ready for xmit
  351.         IN AL,DX
  352.         AND AL,TX_MASK
  353.         CMP AL,TX_MASK
  354.         JNZ RD_RI
  355. TX_55:  MOV AL,$55                    ; Xmit $55, creating 101010.. stream
  356.         MOV DX,SIOBASE+SIO_TX_RX
  357.         OUT DX,AL
  358. RI_0:   MOV AL,0
  359.         MOV [SI+2],AL                 ; 1st RI state will be '0' wait for '1'
  360.         PUSH AX
  361. SAFETY: POP  AX
  362.         MOV AL,1
  363.         SUB [SI+0],AL                 ; but don't wait forever
  364.         JNZ RD_RI
  365.         MOV AL,1
  366.         SUB [SI+1],AL
  367.         JZ EXIT_RI
  368. RD_RI:  MOV DX,SIOBASE+SIO_STAT_I
  369.         IN AL,DX
  370.         PUSH AX
  371.         AND AL,RI_MASK
  372.         CMP [SI+2],AL                 ; Compare to OLD RI state
  373.         JE SAFETY
  374.         MOV AL,0
  375.         MOV [SI+0],AL                 ; Restore safety
  376.         MOV [SI+1],AL
  377. RD_CTS: POP  AX                       ; Get it again
  378.         PUSH AX
  379.         AND AL,RI_MASK
  380.         MOV [SI+2],AL                 ; Save Current RI state
  381.         POP AX
  382. TST_CTS:AND AL,CTS_MASK               ; Test CTS
  383.         CMP AL,CTS_MASK
  384.         JZ  STORE_1                   ; 1
  385.         MOV AL,0                      ; Test if any '1' already seen
  386.         CMP [SI+3],AL
  387.         JNZ STORE_0                   ; 0
  388.         LOOP RD_RI
  389.         JMP EXIT_TIMEOUT              ; Still no '1' seen after $FFFF samples
  390. STORE_1:MOV AL,1
  391.         MOV [SI+3],AL
  392.         STC                           ; 'Carry'
  393. STORE_0:MOV AL,[SI+100+BX]            ; Get buffer contents
  394.         RCL AL,1                      ; Roll into Buffer at [BX]
  395.         PUSHF
  396.         MOV [SI+100+BX],AL
  397.         POPF
  398.         JNC TX_RDY                    ; High bit rolled out ? (1st '1' sample)
  399.         MOV AL,1
  400.         ADD [SI+4],AL                 ; Another Byte-full of samples taken
  401.         JNZ NEXTB
  402.         ADD [SI+5],AL
  403. NEXTB:  DEC BX                        ; Update pointer to current sample
  404.         JNZ STORE_1
  405. S_DONE: NOP                           ; Sample completed
  406.         NOP
  407.                 ; Normal completion ... Sample in $2000+100 -- +100+4FFF
  408.  
  409. EXIT_RI:        ; Had to wait too long for RI to change state => No Freq. avail
  410. EXIT_TIMEOUT:   ; Had RI, but still no '1' sample after $FFFF tries => Empty
  411.  
  412. ---- I typed this in as assembly into a debug session, and tested that.. with
  413.      'proper' results on the sample till some 50k sample rate....
  414.      So it needs a bit of optimization to be able to do 115k2 bit sampling..
  415. ---- Here's the uuencoded irgt.com ---
  416.  
  417. begin 644 irgt.com
  418. MZ?T#D)"0D)"0D)"0D)"0D+K[ ^R0D+":[I"0NO@#L 'N0K  D.Z0D+K[ ^PD
  419. M?^Z0D.G, P                                                  
  420. M                                                            
  421. M                                                            
  422. M                                                            
  423. M                                                            
  424. M                                                            
  425. M                                                            
  426. M                                                            
  427. M                                                            
  428. M                                                            
  429. M                                                            
  430. M                                                            
  431. M                                                            
  432. M                                                            
  433. M                                      "T"5*Z( ?-(5JT3,TAPP  
  434. M                                                            
  435. M                                                            
  436. M                                                            
  437. M                                                      "0D   
  438. M                                                            
  439. M                                                            
  440. M                                             +X (+O_3[D  )"0
  441. MD)"0D)"Z_ .P"NZ0D+K] ^PD(#P@=2ZP5;KX ^ZP (A$ I"0D)"04%BP 2@$
  442. M=1:P 2A$ 71WD)"0D)"0D)"0D)"0D)"0NOX#[% D0#A$ G37L "(!(A$ 5A0
  443. M)$"(1 )8)! \$'0/L  X1 -U$N+6ZSZ0D)"0L &(1 /YD)"0D(J   '0T)R(
  444. M@  !G7. L $ 1 1U$0!$!9"0D)"0D)"0D)"0D)"02W7-ZPZ0D)"0D+0)4KI 
  445. M!\TA6NGZ_0                                                  
  446. M                          "T"5*Z  ?-(5K#                    
  447. M                                                            
  448. M                                                            
  449. M                                                            
  450. M                                                            
  451. M                                                            
  452. M        4DD@+7-A9F5T>2T@5&EM96]U=" -"B0E)24E)24E)25.;W)M86P@
  453. M97AI="P@<V%M<&QE('1A:V5N#0HD)24E)45M<'1Y('-A;7!L92XN+B!N;R M
  454. M,2T@<V5E;B!O;B!#5%,-"B0E)24E)24E)24E)24E)24E)24E)24E)24E)24E
  455. M)24E)24E)24E)24E)24E)24E)24E)24E)24E)24E)24E)24E)24E)24E)24E
  456. M)24E)24E)24E)24E)24E)24E)24E)24E)24E)24E)24E)24E)24E)24E)24E
  457. E)24E)24E)24E)24E)24E)24E)24E)24E)24E)24E)24E)24E)24E
  458.  
  459. end
  460.  
  461. ------
  462. Hoping to get some respons on this.....
  463.  
  464. Thanks in advance,
  465. Gerard.
  466.